package com.futao.springbootlearn20220224.event;

import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;

/**
 * @author futao
 * @date 2022/2/24
 */
@Slf4j
@Component
public class UserRegisterListener implements ApplicationListener<UserRegisterEvent> {

    @Override
    public void onApplicationEvent(UserRegisterEvent event) {
        // 事件传递的数据，用户
        UserRegisterEvent.NewUser newUser = event.getNewUser();
        // 事件发生的时间
        long timestamp = event.getTimestamp();
        // 发生这个事件的对象
        Object source = event.getSource();
        log.info("接收到事件:newUser:{}, timestamp:{}, source:{}", newUser, timestamp, source);
    }
}
